package com.miyuan.wm.controller;

import com.alibaba.fastjson.JSON;
import com.miyuan.wm.request.AddResponsitorysRequestVo;
import com.miyuan.wm.request.QueryRespositorysRequestVo;
import com.miyuan.wm.request.UpdateResponsitorysRequestVo;
import com.miyuan.wm.response.BaseResponse;
import com.miyuan.wm.response.PageResponse;
import com.miyuan.wm.response.QueryGoodsResponseVo;
import com.miyuan.wm.response.QueryRespositorysResponseVo;
import com.miyuan.wm.service.RespositoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName RespositoryController
 * @Description 仓库管理控制
 */
@RestController
@Api(description = "仓库管理控制器", tags = {"仓库管理"})
@RequestMapping(value = "/respository")
@Slf4j
public class RespositoryController {

    @Autowired
    private RespositoryService respositoryService;

    @ApiOperation(value = "获取仓库列表接口")
    @PostMapping("/queryRespositorys")
    public PageResponse<List<QueryRespositorysResponseVo>> listRespositorys(@Valid @RequestBody QueryRespositorysRequestVo requestVo) {
        log.info("获取仓库列表接口请求参数：{}", JSON.toJSONString(requestVo));
        return respositoryService.listRespositorys(requestVo);
    }

    @ApiOperation(value = "新增仓库信息接口")
    @PostMapping("/addRespositorys")
    public BaseResponse<Boolean> addRespositorys(@Valid @RequestBody AddResponsitorysRequestVo requestVo) {
        log.info("新增仓库信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return respositoryService.addRespositorys(requestVo);
    }

    @ApiOperation(value = "修改仓库信息接口")
    @PostMapping("/updateRespositorys")
    public BaseResponse<Boolean> updateRespositorys(@Valid @RequestBody UpdateResponsitorysRequestVo requestVo) {
        log.info("修改仓库信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return respositoryService.updateRespositorys(requestVo);
    }

    @ApiOperation(value = "删除仓库信息接口")
    @PostMapping("/deleteRespositorys")
    public BaseResponse<Boolean> deleteRespositorys(@RequestBody List<Integer> ids) {
        log.info("删除仓库信息接口请求参数：{}", JSON.toJSONString(ids));
        return respositoryService.deleteRespositorys(ids);
    }

    @ApiOperation(value = "查询仓库信息，供下拉框使用")
    @GetMapping("/queryRespositorysforSelect")
    public BaseResponse<List<QueryRespositorysResponseVo>> queryRespositorysforSelect() {
        return respositoryService.queryRespositorysforSelect();
    }

}
